<?php


class Thumb
{
    protected $filename;//文件名
    protected $fileMine;//文件上传类型
    protected $filepath;//文件上传路径
    protected $filemax;//文件上传大小
    protected $fileExt;//文件上传格式
    protected $fileerror;//文件出错设置
    protected $fileflag;//文件检测
    protected $fileinfo; //FILES
    protected $ext; //文件扩展
    protected $path;
//文件上传
    public function __construct($filename="N_File",$filemax=5000000,$filepath="Notices",$fileflag=true,$fileExt=array('gif','jpeg','pjpeg','jpg','png'),$fileMine=array('image/gif','image/jpeg','image/pjpeg','image/jpg','image/png'))
    {
        $this->filename=$filename;
        $this->fileinfo=$_FILES[$this->filename];
        $this->filemax=$filemax;
        $this->filepath=$filepath;
        $this->fileflag=$fileflag;
        $this->fileExt=$fileExt;
        $this->fileMine=$fileMine;
//var_dump($this->filename);
    }

//图片缩略图
    public function Smallimg($x=300,$y=300){
        $imgAtt=getimagesize($this->path);
//图像宽，高，类型
        $imgWidth=$imgAtt[0];
        $imgHeight=$imgAtt[1];
        $imgext=$imgAtt[2];
//等比列缩放
        if(($x/$imgWidth)>($y/$imgHeight)){
            $bl=$y/$imgHeight;
        }else{
            $bl=$x/$imgWidth;
        }
        $x=floor($imgWidth*$bl); //缩放后
        $y=floor($imgHeight*$bl);
        $images=imagecreatetruecolor($x,$y);
        switch($imgext){
            case 1:
                $imageout=imagecreatefromgif($this->path);
                break;
            case 2:
                $imageout=imagecreatefromjpeg($this->path);
                break;
            case 3:
                $imageout=imagecreatefrompng($this->path);
                break;
            default:
                $imageout=imagecreatefromjpeg($this->path);
        }
        imagecopyresized($images,$imageout,0,0,0,0,$x,$y,$imgWidth,$imgHeight);
        $names=555555555555555555555555;
        $this->path=$this->filepath.'/'. $names.'.'.$this->ext;
        imagejpeg($images,$this->path);
        return $this->path;
    }
}